if (isNil "debug") then
{
	debug      = false;
	debugarray = [];
};
ClientSaveVar =
{
	private ["_Fvarname", "_Fvarvalue"];
	_Fvarname  = _this select 0;
	_Fvarvalue = _this select 1;

	if (! (isNull player)) then
	{
		format ["if (isServer) then {[%1, ""%2"", %3] spawn ServerSaveVar;};", player, _Fvarname, _Fvarvalue] call ISSE_pub_execPstr;
	}
	else
	{
		hint "Error: player is Null.";
	};
	
	if (debug) then
	{
		debugarray = debugarray + [ format["Client Saved %1 to %2.", _Fvarname, _Fvarvalue] ];
	};

	true
};

ServerSaveVar =
{
	private ["_c", "_Fplayer", "_Fvarname", "_Fvarvalue", "_Ffound", "_Fvargefunden", "_FnamePlayer", "_location","_skip"];
	_Fplayer      = _this select 0;
	_Fvarname     = _this select 1;
	_Fvarvalue    = _this select 2;
	_FnamePlayer  = name _Fplayer;
	_Ffound       = false;
	_Fvargefunden = true;
	_location = 0;
	if (isNil "serverKontoArray") then {serverKontoArray = [];};
	if (isNil "serverSavedArray") then {serverSavedArray = [];};
	_excludedVars = ["INV_VehicleArray","deadtimes","DeadWaitSec"];
	_pFound = false;
	_skip = false;
	{
		if (_x == _Fvarname) then
		{
			_skip = true;
		};
	} forEach _excludedVars;

	{
		private ["_num", "_arr"];
		_num = _x;
		_arr = call compile format['saved_array_%1', _num];

		if (_arr select 0 == _FnamePlayer) exitWith
		{
			_pFound = true;
			_location = _num;
		};
	} forEach serverSavedArray;

	if (!(_pFound)) then
	{
		_location = (count serverSavedArray);
		serverSavedArray = serverSavedArray + [ _location ]; 
	};
	
	private ["_doesntExist", "_varName"];
	_varName = format["saved_array_%1", _location];
	_doesntExist = isNil _varName;
	
	if (!(_doesntExist)) then
	{
		private ["_data", "_locationInArr"];
		_locationInArr = 1;
		_data = call compile format['saved_array_%1', _location];
		
		if (_skip) then
		{
			_Ffound = true;
		};
		
		_i = 0;
		{
				if (_x == _FvarName) then
				{
					if (!_skip) then
					{
						_locationInArr = _i;
						_varArray = call compile format['saved_array_%1_%2', _location, _locationInArr];
						_varArray set[0, _Fvarvalue];
						_Ffound = true;
						call compile format['saved_array_%1_%2 = %3;', _location, _locationInArr, _varArray];
					}
					else
					{
						_Ffound = true;
					};
				};
			_i = _i + 1;
		} forEach _data;
		
		if (!(_Ffound)) then
		{
			_data = _data + [_FvarName];
			_locationInArr = ((count _data)-1);
			call compile format['saved_array_%1_%2 = [%3];', _location, _locationInArr, _Fvarvalue];
		};
		
		call compile format['saved_array_%1 = %2;',_location,_data];
	}
	else
	{
		_locationInArr = 1;
		if (!_skip) then
		{
			call compile format['saved_array_%1 = ["%2","%3"];', _location,_FnamePlayer, _FvarName];
			call compile format['saved_array_%1_%3 = [%2];', _location, _Fvarvalue, _locationInArr];
		}
		else
		{
			call compile format['saved_array_%1 = ["%2"];', _location,_FnamePlayer];
		};
	};

	_Ffound = false;

	for [{_c=0}, {_c < (count serverKontoArray)}, {_c=_c+1}] do
	{
		if (((serverKontoArray select _c) select 0) == (_FnamePlayer)) then
		{
			_Ffound = true;
		};
	};
	if (!(_Ffound)) then {
		serverKontoArray = serverKontoArray + [ [ (_FnamePlayer) ] ];
		if (debug) then
		{
			debugarray = debugarray + [ format["New Player.", (_FnamePlayer)] ];
		};
	};

	for [{_c=0}, {_c < (count serverKontoArray)}, {_c=_c+1}] do
	{
		if (((serverKontoArray select _c) select 0) == (_FnamePlayer)) then
		{
			_Fvargefunden = false;	
			for [{_b=1}, {_b < (count (serverKontoArray select _c))}, {_b=_b+1}] do
			{
				if ((((serverKontoArray select _c) select _b) select 0) == _Fvarname) then
				{
					(serverKontoArray select _c) set [_b, [_Fvarname, _Fvarvalue]];
					_Fvargefunden = true;
				};	
			};		
			if (not(_Fvargefunden)) then 
			{
				serverKontoArray SET [_c, ((serverKontoArray select _c) + [ [_Fvarname, _Fvarvalue] ])];
			};	
		};	
	};	
	
	if (debug) then {debugarray = debugarray + [ format["Account Stats saved.", (_FnamePlayer)] ];};
	true
};

ClientRequestVar =
{
	JIP_Stats_Ready = false;
	format ["if (isServer) then {[%1] spawn ServerLoadVar;};", player] call ISSE_pub_execPstr;
	true
};
	
ServerClearKonto = {
	private ["_i", "_j", "_k", "_arr", "_return", "_name"];
	_name   = ""; if ((count _this) > 0) then {_name = _this select 0;};
	_return = 0;
	for [{_i=0}, {_i < (count serverKontoArray)}, {_i=_i+1}] do {
		for [{_j=1}, {_j < (count ((serverKontoArray) select _i))}, {_j=_j+1}] do {
			if ( (((serverKontoArray select _i) select 0) == _name) or (_name == "")  ) then {
				if (( typeName (((serverKontoArray select _i) select _j) select 1) ) == "ARRAY") then {
					for [{_k=0}, {_k < (count (((serverKontoArray select _i) select _j) select 1))}, {_k=_k+1}] do {
						if ((typeName ((((serverKontoArray select _i) select _j) select 1) select _k)) == "OBJECT") then {
							if (isNull((((serverKontoArray select _i) select _j) select 1) select _k)) then {
								_arr = (((serverKontoArray select _i) select _j) select 1);
								_arr set [_k, "KontoDeleteString"]; _arr = _arr - ["KontoDeleteString"];
								((serverKontoArray select _i) select _j) set [1, _arr];
								_return = _return + 1;
							};
						};
					};
				};
				if (( typeName (((serverKontoArray select _i) select _j) select 1) ) == "OBJECT") then {
				};
			};
		};
	};
	_return;
};
	
ServerLoadVar = {
	private ["_spieler", "_name", "_found", "_statarray", "_i", "_j", "_k", "_h"];
	_spieler   = (_this select 0);
	_name      = name _spieler;
	_found     = false;
	_statarray = [];
	if (isNil "serverKontoArray") then {serverKontoArray = [];};
	_h = [_name] spawn ServerClearKonto;
	waitUntil{(scriptDone _h)};
	{
	if (_name == (_x select 0)) exitWith {
		_statarray = (_x) - [(_x select 0)];
		if (debug) then {debugarray = debugarray + [format["Known Player loading stats: %1", _x] ];};
		_found = true
	}; 					
	} forEach serverKontoArray;
	format["if (player == %1) then {%2 spawn ClientLoadVar;};", _spieler, _statarray] call ISSE_pub_execPstr; _found
};
	
ClientLoadVar = {
	private ["_c", "_Fvararray"];
	_Fvararray = _this;
	for [{_c=0}, {_c < (count _Fvararray)}, {_c=_c+1}] do {
		call compile format ['%1 = %2;', ((_Fvararray select _c) select 0), ((_Fvararray select _c) select 1)];
	};							
	if (debug) then {debugarray = debugarray + [ "Variables loaded." ];};
	JIP_Stats_Ready = true;
	true
};